package com.duowan.realtime.uniq.algorithm.bloomfilter.util;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.duowan.realtime.uniq.algorithm.bloomfilter.BloomFilter;

public class BloomFilterUtil {

	public static int notContainsCountAndAdd(String group, List<String> values, BloomFilter<String> bloomFilter) {
		int count = 0;
		for (String v : values) {
			if(StringUtils.isBlank(v))  {
				continue;
			}
			
			byte[] bytes = null;
			try {
				bytes = (group + v).getBytes("UTF-8");
				if (bytes!=null && !bloomFilter.contains(bytes)) {
					count ++;
					bloomFilter.add(bytes);
				}
			} catch (UnsupportedEncodingException e) {
				throw new RuntimeException("error",e);
			}
		}
		
		return count;
	}
	
}
